<?php

use common\logic\UserLogic;
use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SearchUserModel */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="user-model-index">


    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['label' => '二维码', 'format' => 'raw', "headerOptions" => ["width" => "140"], 'value' => function ($model) {
                $level = UserLogic::instance()->getRefereeLevel($model);
                if($level == 2){
                    $url = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/user/mobilebind?partner_id={$model->id}";
                }else{
                    $url = "https://api.qrserver.com/v1/create-qr-code/?size=480x480&data=http://pocket.all-star.top/home/partner?partner_id={$model->id}%26grade=2";
                }


                return Html::a("<img src='$url' width='140'>",
                    "$url", ['target' => '_blank']);
            }],
            'nickname',
            'mobile',
            ['label' => '用户数', 'format'=>'raw','value' => function ($model) {
                return Html::a(\common\logic\UserLogic::instance()->getCountByReferee($model->id), \yii\helpers\Url::to(['user', 'referee' => $model->id]));
            }],
            ['label' => '报备数', 'format'=>'raw','value' => function ($model) {
                return Html::a(\common\logic\ReportLogic::instance()->getCountByReferee($model->id), \yii\helpers\Url::to(['report/index', 'referee' => $model->id]));
            }],
            'invite_num',
            'invite_open_num'
            // 'avatar',
            // 'channel',
            // 'create_time:datetime',
            // 'role',
            // 'referee',

        ],
    ]); ?>
</div>
